import QtQuick 1.0
import "../Components"
import "../WebAccess/TwitterAPI.js" as TwitterAPI

//Auth認証のダイアログ
DialogBase {
    id: _root
    width: parent.width
    height: parent.height
    x: 0
    y: 0

    dialogTitle: "Authorization"

    function viewEvent(){
        _inputPIN.text = "";
        _authInfo.text = "Authorized : " + TwitterAPI.getAuthUserName();
    }

    Item {
        x: parent.width * 0.1
        width: parent.width * 0.8
        height: parent.height * 0.8
        anchors.top: _root.titleBottom
        anchors.topMargin: parent.height * 0.1

        Button {
            id: _buttonStartOAuth
            width: parent.width
            height: 25
            x: 0
            y: 0

            text: "1.Get PIN Code"

            onClicked : {
                //oAuth認証開始 PIN取得までしてもらう
                TwitterAPI.startOAuth();
//                console.log("push button")
            }
        }

        Item{
            id: _inputArea
            width: parent.width
            height: _inputPIN.height
            anchors.top: _buttonStartOAuth.bottom
            anchors.topMargin: 10

            Text {
                id: _inputLabel
                anchors.left: parent.left
                height: parent.height
                verticalAlignment: Text.AlignVCenter

                text: "2.PIN ->"
                color: "#ffffff"
            }

            TextBox {
                id: _inputPIN
                width: 100
                height: 20
                anchors.left: _inputLabel.right
                anchors.top: parent.top
                anchors.leftMargin: 5
            }
        }


        //認証ボタン
        Button {
            id: _buttonOAuth
            x: 0
            width: parent.width
            height: 25
            anchors.top: _inputArea.bottom
            anchors.topMargin: 10

            text: "3.Authorization"

            onClicked : {
                //PINで認証する
                TwitterAPI.requestAuthorization(_inputPIN.text);
//                console.log("push button2")
            }
        }

        //認証情報の表示
        Text {
            id: _authInfo
            x: 0
            height: font.pixelSize
            anchors.top: _buttonOAuth.bottom
            anchors.topMargin: 10
            text: "Authorized : " + TwitterAPI.getAuthUserName()
            color: "#ffffff"
        }


        //認証情報クリア
        Button {
            id: _buttonClear
            width: parent.width
            height: 25
            anchors.top: _authInfo.bottom
            anchors.topMargin: 15

            text: "Clear auth"

            onClicked : {
                TwitterAPI.clearAuthInfo();
                viewEvent();
            }
        }

        //閉じる
        Button {
            id: _buttonClose
            width: parent.width
            height: 25
            anchors.top: _buttonClear.bottom
            anchors.topMargin: 15

            text: "Close"

            onClicked : {
                _menuContainer.state = "";
            }
        }
    }


}
